package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.FxyFinancialVoucher;
import com.ruoyi.system.service.impl.FxyFinancialAccountSetsServiceImpl;
import com.ruoyi.system.service.impl.SysUserServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FxyFinancialAccountSets;
import com.ruoyi.system.service.IFxyFinancialAccountSetsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账套Controller
 * 
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/system/sets")
public class FxyFinancialAccountSetsController extends BaseController
{
    @Autowired
    private IFxyFinancialAccountSetsService fxyFinancialAccountSetsService;
    @Autowired
    private SysUserServiceImpl sysUserService;

    /**
     * 查询账套列表
     */
    @PreAuthorize("@ss.hasPermi('system:sets:list')")
    @GetMapping("/list")
    public TableDataInfo list(FxyFinancialAccountSets fxyFinancialAccountSets)
    {
        startPage();
        List<FxyFinancialAccountSets> list = fxyFinancialAccountSetsService.selectFxyFinancialAccountSetsList(fxyFinancialAccountSets);
        return getDataTable(list);
    }

    /**
     * 导出账套列表
     */

    @Log(title = "账套", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxyFinancialAccountSets fxyFinancialAccountSets)
    {
        List<FxyFinancialAccountSets> list = fxyFinancialAccountSetsService.selectFxyFinancialAccountSetsList(fxyFinancialAccountSets);
        ExcelUtil<FxyFinancialAccountSets> util = new ExcelUtil<FxyFinancialAccountSets>(FxyFinancialAccountSets.class);
        util.exportExcel(response, list, "账套数据");
    }

    /**
     * 获取账套详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fxyFinancialAccountSetsService.selectFxyFinancialAccountSetsById(id));
    }

    /**
     * 新增账套
     */

    @Log(title = "账套", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxyFinancialAccountSets fxyFinancialAccountSets)
    {
        return toAjax(fxyFinancialAccountSetsService.insertFxyFinancialAccountSets(fxyFinancialAccountSets));
    }

    /**
     * 修改账套
     */

    @Log(title = "账套", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxyFinancialAccountSets fxyFinancialAccountSets)
    {
        return toAjax(fxyFinancialAccountSetsService.updateFxyFinancialAccountSets(fxyFinancialAccountSets));
    }

    /**
     * 删除账套
     */

    @Log(title = "账套", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fxyFinancialAccountSetsService.deleteFxyFinancialAccountSetsByIds(ids));
    }

	@GetMapping("/getListAccount")
    public AjaxResult getListAccount()
    {
        Long userId = SecurityUtils.getUserId();
        SysUser sysUser = sysUserService.selectUserById(userId);
        Long tenantId = sysUser.getTenantId();

        List<FxyFinancialAccountSets> fxyFinancialAccountSets = fxyFinancialAccountSetsService.selectFxyFinancialAccountSetsById(tenantId);

        return AjaxResult.success("查询成功",fxyFinancialAccountSets);
    }


}
